Constructor: | |
---|---|
Button(master, **options. ) |
Where o master: indicates the parent window. o Options: additional parameters. |
Options | |
---|---|
text | Label of Button |
bd | Border width in pixels. Default is 2. |
bg | background color. |
fg | foreground (text) color. |
activebackground /activeforeground | Background/Foreground color when the button is under the cursor. |
font | Text font to be used for the button's label. |
command | Function or method to be called when the button is clicked. |
Height |
Text Label : Height in letters. Image Label : Height in pixels. |
Widht: |
Text Label : width in letters. Image Label : width in pixels. |
image | Image to be displayed on the button (instead of text) |
padx/pady | Additional padding horizontal / vertical |
relief | Styel of button such as SUNKEN, RAISED, GROOVE, RIDGE etc |
state | Set this option to DISABLED /NORMAL. |
Methods | |
---|---|
config(**options) | Modifies one or more widget options. |
pack( ) | To add button into container(window). |
from tkinter import * def msg(): print("Welcome to CCIT") win=Tk() win.title("CCIT") win.geometry("500x300") btn=Button(win,text="Show",command=msg) btn.pack() win.mainloop()
from tkinter import * from tkinter.messagebox import * def click(): showinfo(title="CCIT",message="Hello World") win=Tk() win.title("CCIT") win.geometry("500x300") btn=Button(win,text="Show",command=click) btn.pack() win.mainloop()
from tkinter import * def msg1(): print("OK Button is Pressed") def msg2(): print("CANCEL Button is Pressed") win=Tk() win.title("CCIT") win.geometry("500x300") b1=Button(win,text="OK",command=msg1) b1.pack() b2=Button(win,text="CANCEL",command=msg2) b2.pack() win.mainloop()